//
//  UIHelper.m
//  xiangqinjiao
//
//  Created by zuqiu on 17/1/18.
//  Copyright © 2017年 zuqiu. All rights reserved.
//

#import "UIHelper.h"
#import "MBProgressHUD.h"
//#import "UIColor+Int.h"

@implementation UIHelper

+ (void)showLoadingInView:(UIView *)view hasText:(BOOL)hasText  {
    UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
    UIView *container = (view != nil ? view : window);
    [self dismissLoadingInView:container];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:container animated:YES];
//    hud.color = [UIColor colorWithHex:0xd78b93];
    if (hasText) {
        hud.labelText = @"加载中...";
        
    }
}

+ (void)showLoadingInView:(UIView *)view {
    [self showLoadingInView:view hasText:NO];
}

+ (void)dismissLoadingInView:(UIView *)view {
    UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
    UIView *container = (view != nil ? view : window);
    [MBProgressHUD hideHUDForView:container animated:YES];
}

+ (void)showTipsWithText:(NSString *)text inView:(UIView *)view {
    
   
    UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
    UIView *container = (view != nil ? view : window);
    [self dismissLoadingInView:container];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:container animated:YES];
    
//    hud.color = [UIColor colorWithHex:0xd78b93];
    // 设置为自定义视图
    hud.mode = MBProgressHUDModeCustomView;
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"info"]];
    hud.detailsLabelFont = [UIFont boldSystemFontOfSize:16];
    hud.detailsLabelText = text;
    
    [hud hide:YES afterDelay:1.5];
}

+ (void)showErrorWithText:(NSString *)text inView:(UIView *)view {
    UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
    UIView *container = (view != nil ? view : window);
    [self dismissLoadingInView:container];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:container animated:YES];
//    hud.color = [UIColor colorWithHex:0xd78b93];
    hud.mode = MBProgressHUDModeCustomView;
    hud.customView = [[UIImageView alloc] initWithImage:  [UIImage imageNamed:@"error"]];
    hud.detailsLabelFont = [UIFont boldSystemFontOfSize:16];
    hud.detailsLabelText = text;
    [hud hide:YES afterDelay:1.5];
}


/**
 *  显示一些信息
 *
 *  @param message 信息内容
 *  @param view    需要显示信息的视图
 *
 */
+ (void)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    [self dismissLoadingInView:view];

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.labelText = message;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
//    hud.detailsLabelText = message;
    // YES代表需要蒙版效果
    hud.dimBackground = NO;
//    [hud hide:YES afterDelay:1.5];

}
+ (void)showdetailMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    [self dismissLoadingInView:view];

    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    hud.detailsLabelText = message;
    // YES代表需要蒙版效果
    hud.dimBackground = NO;
    
}

@end
